package com.leo.service.impl;

import com.leo.bean.Student;
import com.leo.dao.StudentMapper;
import com.leo.service.IStudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author wangss
 */
@Slf4j
@Service("studentService")
@CacheConfig(cacheNames = "student")
public class StudentServiceImpl implements IStudentService {

    @Resource
    private StudentMapper studentMapper;

    @Override
    public int add(Student student) {
        return this.studentMapper.add(student);
    }

    @Override
    public int update(Student student) {
        return this.studentMapper.update(student);
    }

    @Override
    public int deleteBysno(String sno) {
        return this.studentMapper.deleteBysno(sno);
    }

    @Cacheable(key = "#sno")
    @Override
    public Student queryStudentBySno(String sno) {
        log.info("方法 queryStudentBySno 被执行");
        return this.studentMapper.queryStudentBySno(sno);
    }

    @CachePut(key = "#sno", condition = "#result != null")
    @Override
    public Student queryStudentBySnoPut(String sno) {
        log.info("方法 queryStudentBySnoPut 被执行");
        return this.studentMapper.queryStudentBySno(sno);
    }

    @Override
    public List<Student> queryStudent() {
        return studentMapper.queryStudent();
    }

    @Override
    public List<Student> queryStudentGlobal() {
        return studentMapper.queryStudentGlobal();
    }

    @Override
    public int addDynamic(Student student) {
        return studentMapper.addDynamic(student);
    }

}
